<?php include "antet.php"; include "func.php";

if (isset($_SESSION["user"][0], $_GET["town"]))
{
	$to = $_GET["to"]=clean($_GET["to"]);
	$_GET["town"]=clean($_GET["town"]);
	check_r($_GET["town"]);
	check_uup($_GET["town"]);
	$town=town($_GET["town"]);
	if ($town[1]!=$_SESSION["user"][0])
	{
		header('Location: login.php');
		die();
	}
	$faction=faction($_SESSION["user"][10]);
	$r=$faction[3];
	$buildings=buildings($_SESSION["user"][10]);
	$upq=get_up($_GET["town"]);
	$c_status=get_con($_GET["town"]);
	$units=units($faction[0]);
	$uup_status=get_uup($town[0]);
	$weapons=weapons($_SESSION["user"][10]);

	$u_upgrades=explode("-", $town[17]);
	$w_upgrades=explode("-", $town[18]);
	$a_upgrades=explode("-", $town[19]);
	$s_upgrades=explode("-", $town[20]);

	$data=explode("-", $town[8]);
	$res=explode("-", $town[10]);
	$prod=explode("-", $town[9]);
	$lim=explode("-", $town[11]);
$weaps=explode("-", $town[6]);
$wq=get_w($_GET["town"]);
}
else {header('Location: login.php'); die();}
kepala($title." - ".$buildings[17][2]);
?>
<script type="text/javascript">
var res_start0=<?php echo floor($res[0]);?>; var res_start1=<?php echo floor($res[1]);?>; var res_start2=<?php echo floor($res[2]);?>; var res_start3=<?php echo floor($res[3]);?>; var res_start4=<?php echo floor($res[4]);?>;
var res_limit0=<?php echo $lim[0];?>; var res_limit1=<?php echo $lim[1];?>; var res_limit2=<?php echo $lim[1];?>; var res_limit3=<?php echo $lim[1];?>; var res_limit4=<?php echo $lim[2];?>;
var res_ph0=<?php echo ($prod[0]-$town[3]-$town[12]);?>; var res_ph1=<?php echo ($prod[1]);?>; var res_ph2=<?php echo ($prod[2]);?>; var res_ph3=<?php echo ($prod[3]);?>; var res_ph4=<?php echo ($prod[4]);?>;
var res_sec0=0; var res_sec1=0; var res_sec2=0; var res_sec3=0; var res_sec4=0;
</script>
<?php

		$to = 17;
		$output = "";
		$output .= buildingheader($to,$buildings,$data,$lim,$town);
		$output .= ads(0,"top");
		$output .= buildingstandard($town,$to,$lim, $buildings,$faction,$c_status,"good.png",$lang['speed']);
$output .= showweaponlist($town,$lim,$weapons,$weaps);

	//$output .= showproduction($town,$lim);
	//$output .= showbuildinginfo($to,$buildings,showqueue($to,$upq,$units));

				//$output .= "[<a class='q_link' href='cancel_uup.php?town=".$_GET["town"]."&unit=".$upq[$i][1]."&tree=".$upq[$i][2]."'>x</a>] ".$units[$upq[$i][1]][2]." - <span id='".$i."'>".$upq[$i][0]."</span><script type='text/javascript'> var id=new Array(50); timer('".$i."', 'blacksmith.php?town=".$_GET["town"]."'); </script></br>";
			//$uplink = ";

		$cnt = "";$li = "";$no = "";$na = "";$du = "";
		if (count($upq))
		{
			//echo "Weapon forge queue:</br>";
			for ($i=0; $i<count($upq); $i++)
			{
				$cnt++;
				$li[$i] = "cancel_uup.php?town=".$_GET["town"]."&unit=".$upq[$i][1]."&tree=".$upq[$i][2];
				//cancel_w.php?town=".$_GET["town"]."&type=".$wq[$i][1];
				$no[$i] = 1;
				$na[$i] = $units[$upq[$i][1]][2];
				$du[$i] = $upq[$i][0];
				$ret[$i] = "go.php?to=18&town=".$_GET["town"];
			//	echo "[<a class='q_link' href='cancel_w.php?town=".$_GET["town"]."&type=".$wq[$i][1]."'>x</a>] ".$wq[$i][2]." ".$weapons[$wq[$i][1]][2]." - <span id='".$i."'>".$wq[$i][0]."</span><script type='text/javascript'> var id=new Array(50); timer('".$i."', 'stable.php?town=".$_GET["town"]."'); </script></br>";
			}
		}
		$ret[0] = "go.php?to=18&town=".$_GET["town"];
	$output .= showqueue($cnt,$li,$no,$na,$du,$ret);

		$cnt = "";$li = "";$no = "";$na = "";$du = "";
		if (count($wq))
		{
			//echo "Weapon forge queue:</br>";
			for ($i=0; $i<count($wq); $i++)
			{
				$cnt++;

				$ret[$i] = "go.php?town=".$_GET["town"];
				$li[$i] = "cancel_w.php?town=".$_GET["town"]."&type=".$wq[$i][1];
				$no[$i] = $wq[$i][2];
				$na[$i] = $weapons[$wq[$i][1]][2];
				$du[$i] = $wq[$i][0];
			}
		}
		//$output .= showqueue($cnt,$li,$no,$na,$du,$ret);

echo $output;
$output = "";
				$weapons=weapons($_SESSION["user"][10]);
				//$weapons=array(0,1,2,10);
				for ($i=0; $i<count($weapons); $i++)
				{
					if ($i==0 || $i==1 || $i==2 || $i==10)
					{
						$dur=explode(":", $weapons[$i][4]);
						$cost=explode("-", $weapons[$i][3]);
						$co = cost(floor($cost[0]),
							floor($cost[1]),
							floor($cost[2]),
							floor($cost[3]),
							floor($cost[4]),
							($dur[0]*$lim[9]/100).":".($dur[1]*$lim[9]/100));

$form = '<div class="row clearfix">
			<form role="form" name="weapons" method="post" action="forge.php?town='.$_GET["town"].'&type='.$i.'">
				<div class="col-md-6 column"><input class="form-control" name="q" type="text" size="7" maxlength="7" value="1"></div>
				<div class="col-md-6 column"><input type="submit" class="btn btn-block btn-success" name="spear" value="'.$lang["forge"].'"></div>
			</form></div>';
					$output .= boxform("1".$i.".gif",$weapons[$i][2],$weapons[$i][5],$co,$form);

					}
				}
echo $output;
$output = "";


	$output .= "<table class='q_table' style='border-collapse: collapse; text-indent: 0; text-align: center; margin-left: auto; margin-right: auto;' width='600' border='1'>
			<tr>
				<td>".$lang['unitType']."</td>
				<td colspan='3'>". $lang['weapon']."  &  ".$lang['armor']." </td>
			</tr>";
	for ($i=0; $i<count($units); $i++)
	{
		$cost=explode("-", $units[$i][4]);
		if ($w_upgrades[$i]<10)
		{
			$wl="<a class='q_link' href='u_upgrade.php?unit=".$units[$i][0]."&tree=18&town=".$_GET["town"]."'>".$lang['upgrade']." ".$lang['toLevel']." ".($w_upgrades[$i]+1)."</a></br>".$lang['cost'].": <img src='".$imgs.$fimgs."00.gif' title='".
			$lang['crop']."'>".floor($cost[0]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r01.png' title='".
			$lang['lumber']."'>".floor($cost[1]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r02.png' title='".
			$lang['stone']."'>".floor($cost[2]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r03.png' title='".
			$lang['iron']."'>".floor($cost[3]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r04.png' title='".
			$lang['gold']."'>".floor($cost[4]*($w_upgrades[$i]+1))."</br>".
			$lang['duration'].": ".$units[$i][9].", ".$lang['atk'].": ".($units[$i][6]+$w_upgrades[$i]+1);

			$title[0] = "offense.png";
			$title[1] = $lang['weapon'];
			$extra[0] = "r07.png";
			$extra[1] = $lang['atk'];
			$extra[2] = ($units[$i][6]+$w_upgrades[$i]+1);

			$weap = showcost2($title,$w_upgrades[$i],"u_upgrade.php?unit=".$units[$i][0]."&tree=18&town=".$_GET["town"]."'",
			floor($cost[0]*($w_upgrades[$i]+1)),
			floor($cost[1]*($w_upgrades[$i]+1)),
			floor($cost[2]*($w_upgrades[$i]+1)),
			floor($cost[3]*($w_upgrades[$i]+1)),
			floor($cost[4]*($w_upgrades[$i]+1)),
			"plants",$units[$i][9],$extra);
			}
		else
		{
			$wl=$lang['atk'].": ".($units[$i][6]+$w_upgrades[$i]);
		}
		// armour
		if ($a_upgrades[$i]<10)
		{
			$al="<a class='q_link' href='u_upgrade.php?unit=".$units[$i][0]."&tree=19&town=".$_GET["town"]."'>".$lang['upgrade']." ".$lang['toLevel']." ".($a_upgrades[$i]+1)."</a></br>".$lang['cost'].": <img src='".$imgs.$fimgs."00.gif' title='".$lang['crop']."'>".floor($cost[0]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."01.gif' title='".$lang['lumber']."'>".floor($cost[1]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."02.gif' title='".$lang['stone']."'>".floor($cost[2]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."03.gif' title='".$lang['iron']."'>".floor($cost[3]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."04.gif' title='".$lang['gold']."'>".floor($cost[4]*($a_upgrades[$i]+1))."</br>".$lang['duration'].": ".$units[$i][9].", ".$lang['def'].": ".($units[$i][7]+$a_upgrades[$i]+1);
			$title[0] = "defense.png";
			$title[1] = $lang['armor'];
			$extra[0] = "r07.png";
			$extra[1] = $lang['def'];
			$extra[2] = ($units[$i][7]+$a_upgrades[$i]+1);

			$arm = showcost2($title,$a_upgrades[$i],"u_upgrade.php?unit=".$units[$i][0]."&tree=19&town=".$_GET["town"]."'",
			floor($cost[0]*($a_upgrades[$i]+1)),
			floor($cost[1]*($a_upgrades[$i]+1)),
			floor($cost[2]*($a_upgrades[$i]+1)),
			floor($cost[3]*($a_upgrades[$i]+1)),
			floor($cost[4]*($a_upgrades[$i]+1)),
			"plants",$units[$i][9],$extra);
		}
		else
		{
			$al=$lang['def'].": ".($units[$i][7]+$a_upgrades[$i]);
		}
		if (!$uup_status[$i])
		{
			$output .=  "<tr><td><img src='".$imgs.$fimgs."2".$i.".gif' title='".$units[$i][2]."'></td><td>".$units[$i][10]."</td><td>".$weap."</td><td>".$arm."</td></tr>";
		}
		else
		{
			$title[0] = "working.gif";
			$title[1] = $units[$i][2]." ".$lang['upgrading'];
			$d = showcostdisabled($title,$units[$i]);
			$output .= "<tr><td><img src='".$imgs.$fimgs."2".$i.".gif' title='".$units[$i][2]."'></td><td>".$units[$i][10]."</td><td colspan='2'>".$d."</td></tr>";
		}
	} // for
	$output .=  "</table>";
	//echo $output;
	/*		switch ($to)
			{
				case 17:
					echo theblacksmith17();
					break;
				case 18:
					//echo theweaponarmorshop18(clean($_GET["town"]));
					break;
				default:
					echo $lang['constrBuilding'];
			}*/
		$output .= about(); 
		echo $output;
?>

<?php

function thearmoury18()
{
	global $imgs;
	global $fimgs;
	global $lang;
	global $buildings;
	global $units;
	global $lim;
	global $to;
	global $upq;
	global $w_upgrades;
	global $a_upgrades;
	global $faction;
	global $r;
	global $buildings;
	global $c_status;
	global $units;
	global $uup_status;

	$output = "\n";
	$output .= showproduction($lim);
	$output .= showbuildinginfo($to,$buildings,showqueue($to,$upq,$units));
	$output .= "<table class='q_table' style='border-collapse: collapse; text-indent: 0; text-align: center; margin-left: auto; margin-right: auto;' width='600' border='1'>
			<tr>
				<td>".$lang['unitType']."</td>
				<td colspan='3'>". $lang['weapon']."  &  ".$lang['armor']." </td>
			</tr>";
	for ($i=0; $i<count($units); $i++)
	{
		$cost=explode("-", $units[$i][4]);
		if ($w_upgrades[$i]<10)
		{
			$wl="<a class='q_link' href='u_upgrade.php?unit=".$units[$i][0]."&tree=18&town=".$_GET["town"]."'>".$lang['upgrade']." ".$lang['toLevel']." ".($w_upgrades[$i]+1)."</a></br>".$lang['cost'].": <img src='".$imgs.$fimgs."00.gif' title='".
			$lang['crop']."'>".floor($cost[0]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r01.png' title='".
			$lang['lumber']."'>".floor($cost[1]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r02.png' title='".
			$lang['stone']."'>".floor($cost[2]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r03.png' title='".
			$lang['iron']."'>".floor($cost[3]*($w_upgrades[$i]+1))." <img src='".$imgs.$fimgs."r04.png' title='".
			$lang['gold']."'>".floor($cost[4]*($w_upgrades[$i]+1))."</br>".
			$lang['duration'].": ".$units[$i][9].", ".$lang['atk'].": ".($units[$i][6]+$w_upgrades[$i]+1);

			$title[0] = "offense.png";
			$title[1] = $lang['weapon'];
			$extra[0] = "r07.png";
			$extra[1] = $lang['atk'];
			$extra[2] = ($units[$i][6]+$w_upgrades[$i]+1);

			$weap = showcost2($title,$w_upgrades[$i],"u_upgrade.php?unit=".$units[$i][0]."&tree=18&town=".$_GET["town"]."'",
			floor($cost[0]*($w_upgrades[$i]+1)),
			floor($cost[1]*($w_upgrades[$i]+1)),
			floor($cost[2]*($w_upgrades[$i]+1)),
			floor($cost[3]*($w_upgrades[$i]+1)),
			floor($cost[4]*($w_upgrades[$i]+1)),
			"plants",$units[$i][9],$extra);
			}
		else
		{
			$wl=$lang['atk'].": ".($units[$i][6]+$w_upgrades[$i]);
		}
		// armour
		if ($a_upgrades[$i]<10)
		{
			$al="<a class='q_link' href='u_upgrade.php?unit=".$units[$i][0]."&tree=19&town=".$_GET["town"]."'>".$lang['upgrade']." ".$lang['toLevel']." ".($a_upgrades[$i]+1)."</a></br>".$lang['cost'].": <img src='".$imgs.$fimgs."00.gif' title='".$lang['crop']."'>".floor($cost[0]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."01.gif' title='".$lang['lumber']."'>".floor($cost[1]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."02.gif' title='".$lang['stone']."'>".floor($cost[2]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."03.gif' title='".$lang['iron']."'>".floor($cost[3]*($a_upgrades[$i]+1))." <img src='".$imgs.$fimgs."04.gif' title='".$lang['gold']."'>".floor($cost[4]*($a_upgrades[$i]+1))."</br>".$lang['duration'].": ".$units[$i][9].", ".$lang['def'].": ".($units[$i][7]+$a_upgrades[$i]+1);
			$title[0] = "defense.png";
			$title[1] = $lang['armor'];
			$extra[0] = "r07.png";
			$extra[1] = $lang['def'];
			$extra[2] = ($units[$i][7]+$a_upgrades[$i]+1);

			$arm = showcost2($title,$a_upgrades[$i],"u_upgrade.php?unit=".$units[$i][0]."&tree=19&town=".$_GET["town"]."'",
			floor($cost[0]*($a_upgrades[$i]+1)),
			floor($cost[1]*($a_upgrades[$i]+1)),
			floor($cost[2]*($a_upgrades[$i]+1)),
			floor($cost[3]*($a_upgrades[$i]+1)),
			floor($cost[4]*($a_upgrades[$i]+1)),
			"plants",$units[$i][9],$extra);
		}
		else
		{
			$al=$lang['def'].": ".($units[$i][7]+$a_upgrades[$i]);
		}
		if (!$uup_status[$i])
		{
			$output .=  "<tr><td><img src='".$imgs.$fimgs."2".$i.".gif' title='".$units[$i][2]."'></td><td>".$units[$i][10]."</td><td>".$weap."</td><td>".$arm."</td></tr>";
		}
		else
		{
			$title[0] = "working.gif";
			$title[1] = $units[$i][2]." ".$lang['upgrading'];
			$d = showcostdisabled($title,$units[$i]);
			$output .= "<tr><td><img src='".$imgs.$fimgs."2".$i.".gif' title='".$units[$i][2]."'></td><td>".$units[$i][10]."</td><td colspan='2'>".$d."</td></tr>";
		}
	} // for
	$output .=  "</table>";
	return ($output);
}

function theblacksmith17()
{

	return ($output);
}
?>
